package com.good.dao;

import com.good.po.tUser;
import com.good.utils.jdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class tUserDao {
	
	ResultSet rs = null;
	Connection conn = null;
	PreparedStatement ps = null;
	
	public ArrayList<tUser> selectById(String id){
		ArrayList<tUser> list = new ArrayList<>();
		try {
			conn = jdbcUtils.getConn();
			String sql = "select * from t_user where userid = ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, id);
			rs = ps.executeQuery();
			while(rs.next()){
				String uid = rs.getString("userID");
				String name = rs.getString("userName");
				String pwd = rs.getString("pwd");
				tUser tu = new tUser(uid, pwd, name);
				list.add(tu);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			// �ͷ���Դ
			jdbcUtils.close(conn, ps, rs);
		}
		
		return list;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		tUserDao tud = new tUserDao();
		ArrayList<tUser> list = tud.selectById("xxxx@xxxxq.org");
		for(int i=0; i<list.size(); i++){
			tUser tu = list.get(i);
			System.out.println(tu.getuTickName());
		}
	}

}
